package com.happy.unitconvert.common.result;

import java.util.List;

/**
 * 分页结果封装
 * 
 * @param <T> 数据类型
 */
public class PageResult<T> {

  /**
   * 当前页码
   */
  private Integer page;

  /**
   * 每页大小
   */
  private Integer size;

  /**
   * 总记录数
   */
  private Long total;

  /**
   * 总页数
   */
  private Integer pages;

  /**
   * 数据列表
   */
  private List<T> records;

  /**
   * 是否有下一页
   */
  private Boolean hasNext;

  /**
   * 是否有上一页
   */
  private Boolean hasPrevious;

  public PageResult() {
  }

  public PageResult(List<T> records, Integer page, Integer size, Long total) {
    this.records = records;
    this.page = page;
    this.size = size;
    this.total = total;
    this.pages = (int) Math.ceil((double) total / size);
    this.hasNext = page < this.pages;
    this.hasPrevious = page > 1;
  }

  /**
   * 创建分页结果
   */
  public static <T> PageResult<T> of(List<T> records, Integer page, Integer size, Long total) {
    return new PageResult<>(records, page, size, total);
  }

  /**
   * 创建空分页结果
   */
  public static <T> PageResult<T> empty(Integer page, Integer size) {
    return new PageResult<>(List.of(), page, size, 0L);
  }

  // Getters and Setters
  public Integer getPage() {
    return page;
  }

  public void setPage(Integer page) {
    this.page = page;
  }

  public Integer getSize() {
    return size;
  }

  public void setSize(Integer size) {
    this.size = size;
  }

  public Long getTotal() {
    return total;
  }

  public void setTotal(Long total) {
    this.total = total;
  }

  public Integer getPages() {
    return pages;
  }

  public void setPages(Integer pages) {
    this.pages = pages;
  }

  public List<T> getRecords() {
    return records;
  }

  public void setRecords(List<T> records) {
    this.records = records;
  }

  public Boolean getHasNext() {
    return hasNext;
  }

  public void setHasNext(Boolean hasNext) {
    this.hasNext = hasNext;
  }

  public Boolean getHasPrevious() {
    return hasPrevious;
  }

  public void setHasPrevious(Boolean hasPrevious) {
    this.hasPrevious = hasPrevious;
  }
}
